/**
 * 
 */
package com.cipe.cmrs.controllers;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import com.cipe.cmrs.model.Fieldoffice;
import com.cipe.cmrs.service.FieldofficeService;

/**
 * @author Incepio
 *
 */
@Controller
public class FieldofficeController extends BaseController {

	/**
	 * 
	 */
	private static final long	serialVersionUID	= -3823562098119817733L;
	@Autowired
	private FieldofficeService	fieldofficeService;

	@RequestMapping("/secure/saveFieldoffice.do")
	public String SaveFieldoffice(@ModelAttribute("fieldoffice") Fieldoffice fieldoffice, BindingResult result, Model model, HttpServletRequest request) {
		try {
			fieldoffice = fieldofficeService.saveFieldoffice(fieldoffice, getUserId(request));
			saveMessage(request, getText("editFieldoffice.message.success"));
		} catch (Exception e) {
			logger.error(getText("error.transaction"), e);
			saveError(request, getText("error.transaction"));
		}
		model.addAttribute("fieldoffice", fieldoffice);
		return "editFieldoffice";
	}

	@RequestMapping("/secure/showAddFieldoffice.do")
	public String showAddFieldoffice(Model model) {
		model.addAttribute("fieldoffice", new Fieldoffice());
		return "editFieldoffice";
	}

	@RequestMapping("/secure/showEditFieldoffice.do")
	public String showEditFieldoffice(@RequestParam Integer id, Model model) {
		model.addAttribute("fieldoffice", fieldofficeService.findById(id));
		return "editFieldoffice";
	}

	@RequestMapping("/secure/showFieldofficeList.do")
	public String showFieldofficeList(Model model) {
		model.addAttribute("fieldoffices", fieldofficeService.findAll());
		return "fieldofficeList";
	}
}
